package org.opentcs.kcvehicle.communication.kc.udp.agv.param.function.af;

import org.opentcs.kcvehicle.communication.kc.common.byteutils.ByteUtils;

public class TaskStatusInfo {
  private byte[] src;
  //订单 ID
  public Integer orderId;
  //任务 KEY
  public Integer taskKey;
  //点状态序列数量
  public Integer pointStatusNum;
  //段状态序列数量
  public Integer edgeStatusNum;
  //预留,2个字节
  public byte[] remain;
  //点状态序列
  public PointStateSequence[] pointStatusInfo;
  //段状态序列
  public PathStateSequence[] pathStatusInfo;

  public TaskStatusInfo(byte[] src) {
    this.src = src;
    this.orderId = ByteUtils.bytesToInt(src, 0);
    this.taskKey = ByteUtils.bytesToInt(src, 4);

    this.pointStatusNum = ByteUtils.toInt(src[8]);
    this.edgeStatusNum = ByteUtils.toInt(src[9]);
    this.remain = ByteUtils.copyBytes(src, 10, 2);
    if (pointStatusNum > 0) {
      this.pointStatusInfo = new PointStateSequence[pointStatusNum];
      for (int i = 0; i < pointStatusNum; i++) {
        this.pointStatusInfo[i] = new PointStateSequence(ByteUtils.copyBytes(src, 12 + 8 * i, 8));
      }
    }
    if (edgeStatusNum > 0) {
      this.pathStatusInfo = new PathStateSequence[edgeStatusNum];
      for (int i = 0; i < edgeStatusNum; i++) {
        this.pathStatusInfo[i] = new PathStateSequence(
            ByteUtils.copyBytes(src, 12 + pointStatusNum * 8 + 8 * i, 8)
        );
      }
    }
  }
}
